/*===========================================================================+
 |   Copyright (c) 2001, 2005 Oracle Corporation, Redwood Shores, CA, USA    |
 |                         All rights reserved.                              |
 +===========================================================================+
 |  HISTORY                                                                  |
 +===========================================================================*/
package sza.oracle.apps.ap.oie.traveExp.webui;

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;

import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;
import oracle.jbo.ViewObject;

import sza.oracle.apps.ap.oie.traveExp.server.SzaOieCityVOImpl;

/**
 * Controller for ...
 */
public class IntenelExpStandandCO extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
      OAApplicationModule am = pageContext.getApplicationModule(webBean);
      ViewObject vo = am.findViewObject("SzaOieInternalExpStandardVO1");
      
      vo.executeQuery();
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
      OAApplicationModule am = pageContext.getApplicationModule(webBean);
      if("Delete".equalsIgnoreCase(pageContext.getParameter(EVENT_PARAM))){
          String cityId = pageContext.getParameter("standid")+" ";
          ViewObject vo = am.findViewObject("SzaOieInternalExpStandardVO1");
          Row row = null;
          RowSetIterator iterator = vo.createRowSetIterator("deleteIterator");
          int fetchedCount = vo.getFetchedRowCount();
          if(fetchedCount >0){
              iterator.setRangeStart(0);
              iterator.setRangeSize(fetchedCount);
              for(int i=fetchedCount-1;i>-1;i--){
                  row = iterator.getRowAtRangeIndex(i);
                  if(cityId.equals(row.getAttribute("ExpStandardId")+" ")){
                     row.remove();
                  }
              }
          }
          iterator.closeRowSetIterator();
          am.getTransaction().commit();
         pageContext.forwardImmediatelyToCurrentPage(null,false,null);
      } else if("Add".equalsIgnoreCase(pageContext.getParameter(EVENT_PARAM))){
          ViewObject vo = am.findViewObject("SzaOieInternalExpStandardVO1");
          vo.last();
          Row row = vo.createRow();
//          row.setAttribute("EditAble",Boolean.FALSE);
          row.setNewRowState(Row.STATUS_INITIALIZED);
      //          row.setAttribute("DictCode","PAYMENT_TYPE");
          vo.insertRow(row);
      } else if("Save".equalsIgnoreCase(pageContext.getParameter(EVENT_PARAM))){
          am.getTransaction().commit();
      }
  }

}
